**city level HS4 export from China to US

use city_export_usa_2013to2018.dta,clear

gen hs4=substr(hs6,1,4)

ren Year year

collapse (sum) value_city,by(hs4 year)

keep if year==2016


save city_export_usa_hs4_2016.dta,replace


**national level HS4 export from China to US
use "201601-201905中国对美国出口月度HS8.dta",clear

**to a panel database
reshape long value,i(hs*) j(month)

gen hs4=substr(hs8,1,4)

gen year=int(month/100)

keep if year==2016

collapse (sum) value,by(hs4 year)
**merge with city level export
merge 1:1 hs4 year using "city_export_usa_hs4_2016.dta"

keep if _merge==3


gen lnvalue=ln(value*1000)
gen lnvalue_city=ln(value_city)


label var lnvalue_city "log(export value to the U.S. of our sample city)"
label var lnvalue "log(export value to the U.S. of China)"

**scatter plot
graph tw scatter lnvalue_city lnvalue, color(green)|| lfit lnvalue_city lnvalue, ytitle("log(export value to U.S. at the city level)") xtitle("log(export value to U.S. at the country level)") graphregion(color(white) lwidth(large)) legend(off) lcolor(red) ylabel(0(5)25)   


**regression coefficient

reg lnvalue_city lnvalue, r

test _b[lnvalue]=1













